package com.hfmall.controller;


import com.hfmall.entity.*;
import com.hfmall.service.IHfCartService;
import com.hfmall.service.IHfGoodsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liclo
 * @since 2021-08-12
 */
@RestController
@RequestMapping("/cart")
public class HfCartController {
    @Resource
    private IHfCartService cartService;

    @Resource
    private IHfGoodsService goodsService;

    @GetMapping("add")
    public ResponseCode<Void> add(int goods_id,int num){
        HfGoods goods =goodsService.getById(goods_id);
        HfCart cart =new HfCart();
        cart.setGoodsId(goods_id);
        cart.setNumber(num);
        cart.setUserId(1);
        BigDecimal subtotal=goods.getPrice().multiply(BigDecimal.valueOf(num));
        cart.setSubtotal(subtotal);
        cartService.save(cart);
        return new ResponseCode().SUCCESS;

    }
}
